package com.android.serialport;

import android.hardware.usb.UsbDevice;
import android.util.Log;

import com.android.serialport.entity.InventoryBean;
import com.android.serialport.itf.OpenListener;

import java.io.File;
import java.util.List;

/**
 * @author Administrator
 * @date 2021/1/28
 */
public class SerialPortManager {
    private RFIDDevice mRFIDDevice;

    private SerialPortManager() {
        mRFIDDevice = new RFIDDevice("/dev/ttyXRUSB1", 38400, 1, 8, 2, 0, 0);
    }

    private static final class Holder {
        private static final SerialPortManager INSTANCE = new SerialPortManager();
    }

    public static SerialPortManager getInstance() {
        return Holder.INSTANCE;
    }

    public List<UsbDevice> findAllDevice() {
        return null;
    }

    public void openRFIDDevice() {
        mRFIDDevice.open(new OpenListener() {
            @Override
            public void openSucceed(File file) {
                Log.e("openSucceed", file.getAbsolutePath() + "打开成功");
            }

            @Override
            public void onFailed(File file, Status status) {
                Log.e("onFailed", file.getAbsolutePath() + "打开失败");
            }
        });
    }


    public void startInventory() {
        mRFIDDevice.startInventory();
    }

    public void stopInventory() {
        mRFIDDevice.stopInventory();
    }

    public void borrowFlag(List<InventoryBean> list) {
        mRFIDDevice.writeFlag(list, true);
    }

    public void backFlag(List<InventoryBean> list) {
        mRFIDDevice.writeFlag(list, false);
    }


} 